<template>
  <div class="student">
    <h2>姓名：{{name}}</h2>
    <h2>性别：{{sex}}</h2>
    <button @click="sendStudentName">把学生名传给School组件</button>
  </div>
</template>

<script>
//引入发布订阅 pubsub
import pubsub from 'pubsub-js'

export default {
    name: 'Student',
    data() {
        return {
            name: 'zs',
            sex: '男', 
        }
    },
    methods: {
      sendStudentName() {
        //发布消息 消息名 和 数据
        pubsub.publish('hello', this.name)
      }
    },
    mounted() {

    }
}
</script>

<style scoped>
  .student{
      background-color: orange;
      padding: 5px;
      margin-top: 20px;
  }
</style>